package com.way.demo.copybean;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.io.*;

/**
 * @author lipingwei
 * @create 2021-07-21 15:46
 */
@Getter
@Setter
@ToString
public class User implements Serializable {
    private String username;
     private Address address;

     public User myClone() {
         User user = null;
         try {
             ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
             ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
             objectOutputStream.writeObject(this);
             //
             ByteArrayInputStream bytein = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
             ObjectInputStream ois = new ObjectInputStream(bytein);
            user = (User) ois.readObject();
         } catch (Exception e) {
             e.printStackTrace();
         }
         return user;

     }
}
